package com.wude.http;

import android.os.Handler;
import android.os.Message;
import android.util.Base64;
import android.util.Log;

import com.wude.tools.FileUtil;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Map;

public class HttpCom {

    //    public static String URL = "http://www.wudegame.com/app.php?s=";
    public static String URL = "http://app.happysao.com/app.php?s=";//新域名

    //TODO  还有分享的二维码分享需要改
    public static String guize = "活动规则解释权归伍德软件所有";
    public static String fenxiang = "邀请您的好友下载游戏并进行现金充值，您将会获得充值支付金额5%的快乐币邀请奖励，每位好友给您的奖励100快乐币封顶，邀请人数不限";

    public static void setURL(String URL) {
        HttpCom.URL = URL;
    }

    /**
     * @return SD卡储存文件名
     */
    public static String getFeilName() {
        return "WudeGame";
    }

    /**
     * @return 微信官方APPID
     */
    public static String getAppId() {
        return "wxf32cbef7e9ffc383";
    }

    /**
     * @return 下载管理中删除下载所需的包名路径
     */
    public static String getDeownloadCenter() {
        return "class com.wude.guild.activity.four.DownloadActivity";
    }

    /**
     * @return 注册协议
     */
    public static String getXieYi() {
        return "http://www.wudegame.com/media.php?s=/Article/agreement1.html";
    }

    /**
     * @return 下载服务
     */
    public static String getDownServer() {
        return "com.wude.guild.manager.DownloadManager";
    }

    /**
     * @return 启动页面图片
     */
    public static String getShanPingURL() {
        return URL + "user/open_picture";
    }

    /**
     * @return 获取轮播图数据
     */
    public static String getTopTuURL() {
        return URL + "Adv/get_slider";
    }

    /**
     * @return 版本检测，关于我们
     */
    public static String getVisonURL() {
        return URL + "Base/about_us";
    }

    /**
     * @return 修改密码
     */
    public static String getPasswordURL() {
        return URL + "user/change_pwd";
    }

    /**
     * @return 获取用户信息
     */
    public static String getUserInfoUrl() {
        return URL + "user/get_user_info";
    }

    /**
     * @return 编辑更新用户信息
     */
    public static String getUserURL() {
        return URL + "user/update_user";
    }

    /**
     * @return 发送验证码
     */
    public static String getYanzhengURL() {
        return URL + "user/send_msg";
    }

    /**
     * @return 绑币记录
     */
    public static String getBBJLURL() {
        return URL + "User/get_user_bind_coin";
    }

    /**
     * @return 我的收藏
     */
    public static String getSCURL() {
        return URL + "Game/my_collect_game";
    }

    /**
     * @return 删除礼包
     */
    public static String getDelGiftURL() {
        return URL + "Gift/delete_gift_record";
    }

    /**
     * @return 我的评论
     */
    public static String getMyPinglunURL() {
        return URL + "Comment/my_comment";
    }

    /**
     * @return 排行榜
     */
    public static String getRankingURL() {
        return URL + "game/get_game_rank_lists";
    }

    /**
     * @return 获取折扣信息
     */
    public static String getDiscountURL() {
        return URL + "Game/get_game_recharge_discount";
    }

    /**
     * @return 获取可代充的游戏列表
     */
    public static String getDCGameURL() {
        return URL + "Game/get_user_recharge_game";
    }

    /**
     * @return 获取下载链接
     */
    public static String getDownURL() {
        return URL + "Down/down";
    }

    /**
     * @return 用户密码登录
     */
    public static String getUserLoginURL() {
        return URL + "user/user_login";
    }

    /**
     * @return 用户验证码登录
     */
    public static String getUserCodeLoginURL() {
        return URL + "user/user_sms_login";
    }

    /**
     * @return 用户注册
     */
    public static String getUserResgiterURL() {
        return URL + "user/user_phone_register";
    }

    /**
     * @return 忘记密码
     */
    public static String getUserForgetPassURL() {
        return URL + "user/forget_password";
    }

    /**
     * @return 忘记密码发送验证码接口
     */
    public static String getUserForgetPassmsgURL() {
        return URL + "user/forget_send_msg";
    }

    /**
     * @return 收藏游戏
     */
    public static String getShouCangUrl() {
        return URL + "Game/collect_game";
    }

    /**
     * @return 支付宝支付
     */
    public static String getPayUrl() {
        return URL + "Pay/recharge";
    }

    /**
     * @return 实名认证提交名字身份证号
     */
    public static String getRenZheng() {
        return URL + "User/idcard_change";
    }

    /**
     * @return 游戏详情页面
     */
    public static String getGameDetUrl() {
        return URL + "Game/get_game_detail";
    }

    /**
     * @return 游戏详情礼包列表页面
     */
    public static String getGameDetGiftUrl() {
        return URL + "Gift/get_gift_lists";
    }

    /**
     * @return 游戏详情开服列表页面
     */
    public static String getGameDetKaifuUrl() {
        return URL + "Server/get_server_lists";
    }

    /**
     * @return 游戏详情评论列表页面
     */
    public static String getGameDetPingLunUrl() {
        return URL + "comment/get_comment";
    }

    /**
     * @return 游戏详情发表评论
     */
    public static String getGameDetFBPLUrl() {
        return URL + "comment/add_comment";
    }

    /**
     * @return 领取激活码
     */
    public static String getLingQuUrl() {
        return URL + "Gift/get_novice";
    }

    /**
     * @return 我的礼包
     */
    public static String getMyGiftURL() {
        return URL + "Gift/get_my_gift_record";
    }

    /**
     * @return 礼包详情
     */
    public static String getGiftDetURL() {
        return URL + "Gift/get_detail";
    }


    /**
     * @return 分享获取积分
     */
    public static String getShareJifenUrl() {
        return URL + "points/add_point_by_type";
    }

    /**
     * @return 获取用户邀请奖励
     */
    public static String getYaoURL() {
        return URL + "Share/get_user_invite_info";
    }

    /**
     * @return 我的邀请
     */
    public static String getMyYaoqingURL() {
        return URL + "Share/get_my_invite_record";
    }

    /**
     * @return 获取游戏分享信息
     */
    public static String getGameShareURL() {
        return URL + "Game/get_share_info";
    }

    /**
     * @return 改变默认收货地址
     */
    public static String getChageAddressURL() {
        return URL + "UserAddress/set_default";
    }

    /**
     * @return 编辑收货地址
     */
    public static String getBJAddressURL() {
        return URL + "UserAddress/edit";
    }

    /**
     * @return 删除收货地址
     */
    public static String getDelAddressURL() {
        return URL + "UserAddress/delete";
    }

    /**
     * @return 获取收货地址
     */
    public static String getHuoQuAddressURL() {
        return URL + "UserAddress/get_lists";
    }

    /**
     * @return 保存收货地址
     */
    public static String getSaveAddressURL() {
        return URL + "UserAddress/add";
    }

    /**
     * @return 流量列表
     */
    public static String getFlowList() {
        return URL + "flow/get_day_list";
    }

    /**
     * @return 领取流量
     */
    public static String getGetFlow() {
        return URL + "flow/get_day_flow";
    }


    /**
     * @return 优惠券列表
     */
    public static String getCouponList() {
        return URL + "Coupon/show_all_coupon";
    }

    /**
     * @return 领取优惠券
     */
    public static String getGetCoupon() {
        return URL + "Coupon/receive_coupon";
    }

    /**
     * @return 我的优惠券列表
     */
    public static String getMyCouponList() {
        return URL + "Coupon/my_coupon";
    }

    /**
     * @return 是否打开支付功能
     */
    public static String getIsPay() {
        return URL + "Pay/check_payui";
    }

    /**
     * @return 推广游戏列表
     */
    public static String getGeneralize() {
        return URL + "channel/my_game";
    }

    /**
     * @return 动态列表
     */
    public static String getCommentaries() {
        return URL + "dynamic/get_lists";
    }


    /**
     * @return 图片上传
     */
    public static String getImgUpload() {
        return URL + "comment/upload_picture";
    }

    /**
     * @return 提取流量选项
     */
    public static String getGetUserFlowListw() {
        return URL + "flow/get_user_flow_list";
    }

    /**
     * @return 提取流量
     */
    public static String getGetUserFlowReceive() {
        return URL + "flow/get_user_flow_receive";
    }

    public static String getGetLottery() {
        return URL + "lottery/get_lottery";
    }

    /**
     * @return 中奖信息
     */
    public static String getGetLotteryPrize() {
        return URL + "lottery/get_prize";
    }

    /**
     * @return 首页跑马灯
     */
    public static String getGetNotice() {
        return URL + "adv/get_notice";
    }

    /**
     * @return 中奖名单
     */
    public static String getGetLotteryList() {
        return URL + "lottery/get_prize_list";
    }

    /**
     * @return 绑卡文案
     */
    public static String getGetActivityText() {
        return URL + "Activity/get_write_text";
    }

    /**
     * @return 联通、电信活动用户判断
     */
    public static String getGetUserStatus() {
        return URL + "user/get_user_status";
    }

    /**
     * @return 绑卡操作
     */
    public static String getBindPhone() {
        return URL + "Activity/bind_phone";
    }

    /**
     * @return 绑卡验证码
     */
    public static String getBindPhoneAuthCode() {
        return URL + "Activity/send_msg";
    }

    /**
     * @return 问题与建议
     */
    public static String getQuestionSuggest() {
        return URL + "base/question_suggest";
    }

    /**
     * @return 活动分享链接
     */
    public static String getActivityShare() {
        return URL + "Activity/share";
    }

    /**
     * @return 活动礼包列表
     */
    public static String getActivityGiftList() {
        return URL + "Activity/get_gift";
    }

    /**
     * @return 领取礼包
     */
    public static String getActivityGetNovice() {
        return URL + "Activity/get_novice";
    }

    /**
     * @return 福利红点
     */
    public static String getGetRedIconStatus() {
        return URL + "user/getRedIconStatus";
    }

    /**
     * @return 获取用户信息
     */
    public static String getGetUserInfo() {
        return URL + "user/getUserInfo";
    }

    /**
     * @return 获取每日任务列表
     */
    public static String getGetTask() {
        return URL + "Dailymission/get_list";
    }

    /**
     * @return 流量明细
     */
    public static String getGetFlowDetail() {
        return URL + "flow/get_flow_details";
    }

    /**
     * @return 积分明细
     */
    public static String getGetPointDetail() {
        return URL + "points/get_point_details";
    }

    /**
     * @return 积分兑换明细
     */
    public static String getGetPointShopRecordDetails() {
        return URL + "PointShop/getPointShopRecordDetails";
    }

    /**
     * @return 完成所有任务获取积分
     */
    public static String getGetUserDailyMission() {
        return URL + "points/getUserDailyMission";
    }

    /**
     * @return 积分商城商品列表
     */
    public static String getGetPointShopList() {
        return URL + "PointShop/get_lists";
    }

    /**
     * @return 积分商城商品列表
     */
    public static String getGetPointShop() {
        return URL + "PointShop/getPointShop";
    }

    /**
     * @return 联通领取话费
     */
    public static String getReceiveCalls() {
        return URL + "activity/receive_calls";
    }


    //    public static String FeilName = "WudeGame";                                        //SD卡储存文件名
//    public static String AppId = "wxf32cbef7e9ffc383";                                //微信官方APPID
//    public static String DeownloadCenter = "class com.wude.guild.activity.four.DownloadActivity";  //下载管理中删除下载所需的包名路径
//    public static String XieYi = "http://www.wudegame.com/media.php?s=/Article/agreement1.html";      //注册协议
//    public static String DownServer = "com.wude.guild.manager.DownloadManager";      //下载服务

    //    public static String ShanPingURL = URL + "user/open_picture";   //启动页面图片
    public static String HomePagerURL = URL + "Game/get_home_recommend";                            //首页游戏列表
    //    public static String TopTuURL = URL + "Adv/get_slider";                            //获取轮播图数据
    public static String SreachUrl = URL + "Game/get_game_lists_by_name";                            //游戏搜索
    //    public static String VisonURL = URL + "Base/about_us";                                //版本检测，关于我们
//    public static String PasswordURL = URL + "user/change_pwd";                                //修改密码
//    public static String UserInfoUrl = URL + "user/get_user_info";                        //获取用户信息
//    public static String UserURL = URL + "user/update_user";                                    //编辑更新用户信息
//    public static String YanzhengURL = URL + "user/send_msg";                                    //发送验证码
//    public static String BBJLURL = URL + "User/get_user_bind_coin";                                    //绑币记录
//    public static String SCURL = URL + "Game/my_collect_game";                                    //我的收藏
    public static String JFZNURL = URL + "Point/point_guide";                                    //积分指南
    //    public static String DelGiftURL = URL + "Gift/delete_gift_record";                                    //删除礼包
//    public static String MyPinglunURL = URL + "Comment/my_comment";                                    //我的评论
    public static String SignURL = URL + "Point/sign_in";                                            //签到
    public static String GameFenURL = URL + "Game/get_game_type_lists";                                            //游戏分类列表
    public static String GameFenDelURL = URL + "Game/get_game_lists_by_type";                                            //游戏分类详情列表
    public static String StartServerURL = URL + "Server/get_lists";                                //开服表
    //    public static String RankingURL = URL + "game/get_game_rank_lists";                                            //排行榜
//    public static String DiscountURL = URL + "Game/get_game_recharge_discount";                                            //获取折扣信息
//    public static String DCGameURL = URL + "Game/get_user_recharge_game";                                            //获取可代充的游戏列表
//    public static String GetdownURL = URL + "Down/down";                        //获取下载链接
//    public static String UserLoginURL = URL + "user/user_login";                        //用户密码登录
//    public static String UserCodeLoginURL = URL + "user/user_sms_login";                        //用户验证码登录
    public static String TouXiangURL = URL + "Files/upload_head";                        //上传头像
    //    public static String UserResgiterURL = URL + "user/user_phone_register";                        //用户注册
//    public static String UserForgetPassURL = URL + "user/forget_password";                        //忘记密码
    public static String UserChagePassURL = URL + "user/forget_password";                        //修改密码
    //    public static String UserForgetPassmsgURL = URL + "user/forget_send_msg";                        //忘记密码发送验证码接口
    public static String WFTpay = URL + "";                        //威富通支付

    //    public static String ShouCangUrl = URL + "Game/collect_game";                        //收藏游戏
    public static String ZhuanQuUrl = URL + "Game/get_discount_game_lists";                        //折扣专区页面游戏
//    public static String PayUrl = URL + "Pay/recharge";                        //支付宝支付
//    public static String RenZheng = URL + "User/idcard_change";        //实名认证提交名字身份证号

    //游戏详情
//    public static String GameDetUrl = URL + "Game/get_game_detail";                            //游戏详情页面
//    public static String GameDetGiftUrl = URL + "Gift/get_gift_lists";                        //游戏详情礼包列表页面
//    public static String GameDetKaifuUrl = URL + "Server/get_server_lists";                    //游戏详情开服列表页面
//    public static String GameDetPingLunUrl = URL + "comment/get_comment";                        //游戏详情评论列表页面
//    public static String GameDetFBPLUrl = URL + "comment/add_comment";                        //游戏详情发表评论

    //资讯相关
    public static String Information = URL + "Article/get_article_lists";                    //资讯

    //礼包相关
//    public static String LingQuUrl = URL + "Gift/get_novice";                                    //领取激活码
    public static String GiftSreachURL = URL + "Gift/gift_lists_num";                            //礼包搜索
//    public static String MyGiftURL = URL + "Gift/get_my_gift_record";                            //我的礼包
//    public static String GiftDetURL = URL + "Gift/get_detail";                                //礼包详情

    //积分相关
    public static String JFJLURL = URL + "Point/get_user_data";                                    //积分获取.使用记录
    public static String MyDHJLURL = URL + "PointShop/get_user_buy_record";                        //积分兑换记录
    public static String JifenXinURL = URL + "Point/get_sign_in";                                    //积分信息
    public static String JifenDuiURL = URL + "PointShop/point_convert_coin";                        //积分兑换平台币
    public static String ZJifenURL = URL + "Point/get_user_spend_point";                            //获取用户消费积分

    //分享相关
//    public static String ShareJifenUrl = URL + "points/add_point_by_type";                                //分享获取积分
//    public static String YaoURL = URL + "Share/get_user_invite_info";                                    //获取用户邀请奖励
//    public static String MyYaoqingURL = URL + "Share/get_my_invite_record";                            //我的邀请
    public static String ShareURL = URL + "Share/get_share_url";                                        //获取分享链接
    //    public static String GameShareURL = URL + "Game/get_share_info";                                    //获取游戏分享信息
    public static String WenShareURL = URL + "Article/get_share_info";                                //获取文章分享信息

    //收货地址相关
//    public static String ChageAddressURL = URL + "UserAddress/set_default";                            //改变默认收货地址
//    public static String BJAddressURL = URL + "UserAddress/edit";                                        //编辑收货地址
//    public static String DelAddressURL = URL + "UserAddress/delete";                                    //删除收货地址
//    public static String HuoQuAddressURL = URL + "UserAddress/get_lists";                                //获取收货地址
//    public static String SaveAddressURL = URL + "UserAddress/add";                                    //保存收货地址
    public static String DefaultAddressURL = URL + "UserAddress/get_default";                            //获取默认收货地址

    //商品相关
    public static String ShoplieUrl = URL + "PointShop/get_lists";                                    //获取商品列表
    public static String ShopDetUrl = URL + "PointShop/get_data";                                        //商品详情
    public static String ShopJiLuUrl = URL + "PointShop/get_user_buy_record";                            //商品兑换记录
    public static String BuyShopUrl = URL + "PointShop/buy";                                            //购买商品
    public static String BuyShopDetUrl = URL + "PointShop/get_buy_record_detail";                        //购买记录详情

    //定制内容
//    public static String FlowList = URL + "flow/get_day_list";   //流量列表
//    public static String GetFlow = URL + "flow/get_day_flow";  //领取流量
    public static String MyFlow = URL + "Flow/my_flow_list";  //我的流量列表
    public static String ExtractFlow = URL + "Flow/pick_flow";  // 提取流量
    //    public static String CouponList = URL + "Coupon/show_all_coupon";   //优惠券列表
//    public static String GetCoupon = URL + "Coupon/receive_coupon";     //领取优惠券
//    public static String MyCouponList = URL + "Coupon/my_coupon";       //我的优惠券列表
    private static FileUtil fileUtil;


    //    public static String isPay = URL + "Pay/check_payui";       //是否打开支付功能
//    public static String generalize = URL + "channel/my_game"; //推广游戏列表
    public static String payList = URL + "boon/get_boon_list"; //充值列表
    //    public static String commentaries = URL + "dynamic/get_lists"; //动态列表
//    public static String imgUpload = URL + "comment/upload_picture"; //图片上传
//    public static String getUserFlowListw = URL + "flow/get_user_flow_list"; //提取流量选项
//    public static String getUserFlowReceive = URL + "flow/get_user_flow_receive"; //提取流量
//    public static String getLottery = URL + "lottery/get_lottery";
//    public static String getLotteryPrize = URL + "lottery/get_prize"; //中奖信息
//    public static String getNotice = URL + "adv/get_notice"; //首页跑马灯
//    public static String getLotteryList = URL + "lottery/get_prize_list"; //中奖名单
//    public static String getActivityText = URL + "Activity/get_write_text"; //绑卡文案
//    public static String getUserStatus = URL + "user/get_user_status"; //联通、电信活动用户判断
//    public static String bindPhone = URL + "Activity/bind_phone"; //绑卡操作
//    public static String bindPhoneAuthCode = URL + "Activity/send_msg"; //绑卡验证码
//    public static String questionSuggest = URL + "base/question_suggest"; //问题与建议
//    public static String activityShare = URL + "Activity/share"; //活动分享链接
//    public static String activityGiftList = URL + "Activity/get_gift"; //活动礼包列表
//    public static String activityGetNovice = URL + "Activity/get_novice"; //领取礼包
//    public static String getRedIconStatus = URL + "user/getRedIconStatus"; // 福利红点
//    public static String getUserInfo = URL + "user/getUserInfo"; //获取用户信息
//    public static String getTask = URL + "Dailymission/get_list"; //获取每日任务列表
//    public static String getFlowDetail = URL + "flow/get_flow_details"; //流量明细
//    public static String getPointDetail = URL + "points/get_point_details"; //积分明细
//    public static String getPointShopRecordDetails = URL + "PointShop/getPointShopRecordDetails";//积分兑换明细
//    public static String getUserDailyMission = URL + "points/getUserDailyMission"; //完成所有任务获取积分
//    public static String getPointShopList = URL + "PointShop/get_lists";//积分商城商品列表
//    public static String getPointShop = URL + "PointShop/getPointShop";//积分商城商品列表

    /**
     * Post网络请求
     *
     * @param url
     * @return
     */
    public static void POST(final Handler handler, String url, Map<String, String> map, final boolean aa) {
        RequestParams params = new RequestParams(url);
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                if (aa) {
                    String encodeToString = Base64.encodeToString(entry.getValue().getBytes(), Base64.DEFAULT);
                    params.addBodyParameter(entry.getKey(), encodeToString);
                } else {
                    params.addBodyParameter(entry.getKey(), entry.getValue());
                }
            }
        }
        Log.e("请求参数", params.toString());
        if (fileUtil == null) {
            fileUtil = new FileUtil();
        }
        String promoteId = fileUtil.getPromoteId();
        Log.e("获取渠道ID", "" + promoteId);
        params.addBodyParameter("promote_id", promoteId);
        final Message msg = new Message();
        x.http().post(params, new Callback.CacheCallback<String>() {
            @Override
            public void onCancelled(CancelledException arg0) {
            }

            @Override
            public void onError(Throwable arg0, boolean arg1) {
                Log.e("POST错误信息", arg0.toString());
                msg.what = 2;
                handler.sendMessage(msg);
            }

            @Override
            public void onFinished() {
            }

            @Override
            public void onSuccess(String json) {
                msg.what = 1;
                try {
                    if (aa) {
                        Log.e("返回数据", json);
                        String result = new String(Base64.decode(json, Base64.DEFAULT), "utf-8");
                        msg.obj = result;
                        handler.sendMessage(msg);
                    } else {
                        if (json != null && json.startsWith("\ufeff")) {
                            json = json.substring(1);
                        }
                        msg.obj = json;
                        handler.sendMessage(msg);
                    }
                    Log.d("返回json", msg.obj.toString());
                } catch (Exception e) {
                    Log.e("POST+json成功回调出错：", e.toString());
                }
            }

            @Override
            public boolean onCache(String json) {
                msg.what = 1;
                try {
                    String result = new String(Base64.decode(json, Base64.DEFAULT), "utf-8");
                    msg.obj = result;
                    handler.sendMessage(msg);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    Log.e("POST+json缓存回调出错：", e.toString());
                }
                return true;
            }
        });
    }

    /**
     * Post网络请求
     *
     * @param url
     * @return
     */
    public static void POSTFile(final Handler handler, String url, String token, File fileValue) {

        RequestParams params = new RequestParams(url);
        params.addBodyParameter("token", token);
        params.addBodyParameter("image", fileValue);

        Log.e("请求参数", params.toString());
        if (fileUtil == null) {
            fileUtil = new FileUtil();
        }
        String promoteId = fileUtil.getPromoteId();
        Log.e("获取渠道ID", "" + promoteId);
        params.addBodyParameter("promote_id", promoteId);
        final Message msg = new Message();
        x.http().post(params, new Callback.CacheCallback<String>() {
            @Override
            public void onCancelled(CancelledException arg0) {
            }

            @Override
            public void onError(Throwable arg0, boolean arg1) {
                Log.e("POST错误信息", arg0.toString());
                msg.what = 2;
                handler.sendMessage(msg);
            }

            @Override
            public void onFinished() {
            }

            @Override
            public void onSuccess(String json) {
                msg.what = 1;
                try {
                    if (json != null && json.startsWith("\ufeff")) {
                        json = json.substring(1);
                    }
                    msg.obj = json;
                    handler.sendMessage(msg);
                } catch (Exception e) {
                    Log.e("POST+json成功回调出错：", e.toString());
                }
            }

            @Override
            public boolean onCache(String json) {
                msg.what = 1;
                try {
                    String result = new String(Base64.decode(json, Base64.DEFAULT), "utf-8");
                    msg.obj = result;
                    handler.sendMessage(msg);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    Log.e("POST+json缓存回调出错：", e.toString());
                }
                return true;
            }
        });
    }
}
